<?php
/**
 * Created by PhpStorm.
 * User: THUNDEROBOT
 * Date: 2021/1/11
 * Time: 11:04
 */

namespace app\admin\controller;


use app\admin\model\Teacher;
use think\Controller;
use think\Request;
use think\Config;

class Teachers extends Controller
{
    public function index(){
        $teacherModel = new Teacher();
        $teacherList = $teacherModel->teacher();
//         dump($teacherList->toArray());
        $emptyHtml = '<tr><td align="center" colspan="5">暂无任何数据</td></tr>';
        $this->assign("emptyHtml",$emptyHtml);
        $this->assign("teacherList",$teacherList);
        return $this->fetch();
    }

    //编辑密码
    public function editteacher(){
        if(Request::instance()->isGet()){
            $id = Request::instance()->get("id");
            $userModel = new Teacher();
            $Data = $userModel->editteacher($id);
            $this->assign("id",$Data);
            $this->assign("t_name",$Data);
//            $this->assign("t_username",$Data);
            $this->assign("t_password",$Data);
        }
        return $this->fetch("editteacher");
    }

    //提交编辑密码
    public function doEditteacher(){
        if(Request::instance()->isPost()){
            $userDate = Request::instance()->post();
//            dump($userDate);
            $userModel = new Teacher();
            $re = $userModel->doEditteacher($userDate);
            if($re){
                $this->success("修改成功",'admin/teachers/index');
            }else{
                $this->error("修改失败");
            }
        }
    }

}